<?php
if (!defined('BASEPATH'))
	exit ('No direct script access allowed');

class Add extends CI_Controller {
	var $data;
	function __construct() {
		parent :: __construct();
		if ($this->session->userdata('userid') == FALSE) {
			Header("Location:" . site_url('welcome'));
			exit ();
		}
		$this->data['username'] = $this->session->userdata('username');
	}
	function index() {
		parse_str($_SERVER['QUERY_STRING'], $_GET);
		$id = isset ($_GET['id']) ? $_GET['id'] : '';
		$this->load->library('ckeditor');
		$this->load->library('ckFinder');
		$this->ckeditor = new CKEditor();
		$this->ckeditor->basePath = '/js/ckeditor/';
		$this->ckeditor->config['toolbar'] = 'Full';
		$this->ckeditor->config['language'] = 'zh-cn'; // $this -> ckeditor -> config[''] 添加一些你需要的配置详细参数自己查一下
		CKFinder :: SetupCKEditor($this->ckeditor, '/js/ckfinder/');
		$this->load->view('admin/add');
	}
	function insert() {
		$this->datas['title'] = $_POST['title'];
		$this->datas['class_id'] = $_POST['class_id'];
		$this->datas['writer'] = $_POST['writer'];
		$this->datas['description'] = $_POST['description'];
		$this->datas['content'] = $_POST['mailtpl_content'];
$str= $_POST['mailtpl_content'];//文章内容（包括图片）
if(preg_match_all("/<img .*\/>/isU",$str,$ereg))
{
preg_match_all("/<img .*\/>/isU",$str,$ereg);//把图片的<img 整个都获取出来了
$img  = $ereg[0][0];//图片
preg_match_all ('|src="(.*)"|isU', $img, $img1);
$img_path = $img1[1][0];//获取第一张图片路径
$this->datas['pic'] = $img_path;
}
		$this->datas['createdate'] = time();
		$this->db->insert('info', $this->datas);
		$this->message['message_info'] = '信息添加成功，将回到添加页面继续添加！';
		$this->message['message_url'] = site_url('admin/add');
		$this->load->view('admin/message', $this->message);
	}
}